﻿Imports DAO
Imports DTO
Imports System.Data
Imports System.Data.OleDb
Public Class DoanhThuTrongNgayDAO
    Public Function SBNTrongNgay(ByVal ngay As Date) As Long
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = cnn
        cmd.CommandText = "select count(PKB.MaPhieu) from DanhSachKhamBenh DSKB,PHIEUKHAMBENH PKB where DSKB.NgayKham=@ngaykham PKB.MaBenhNhan=DSKB.MaBenhNhan "
        Dim para As OleDbParameter
        para = cmd.Parameters.Add("@ngaykham", OleDbType.Date)
        para.Value = ngay
        Dim temp As Long
        temp = cmd.ExecuteScalar()
        Return temp
    End Function
    Public Function TIENTHUOC(ByVal MaThuoc As Long, ByVal soluong As Long) As Long
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = cnn
        cmd.CommandText = " select DonGia from THUOC where MaThuoc=" + MaThuoc + " "
        

        Dim temp As Long
        temp = cmd.ExecuteScalar()
        Return (temp * soluong)
    End Function
    ' lay ra doanh thu ngay truoc
    Public Function DOANHTHUNGAYTRUOC(ByVal ngaytruoc As Date) As Long
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = cnn
        cmd.CommandText = " select DoanhThu from DOANHTHUTRONGNGAY where NgayKhamNam=" + ngaytruoc + " "


        Dim temp As Long
        temp = cmd.ExecuteScalar()
        Return temp
    End Function
    '
    Public Function INSERT(ByVal doanhthu As DoanhThuTrongNgayDTO) As Integer
        ' Dim query As String
        Dim DTP As New DataProvider()
        'tao ket noi
        Dim _cnn As OleDbConnection = DTP.ConnectDB()
        'mo ket noi
        _cnn.Open()
        'tao cau lenh command
        'SqlCommand(cmd = New SqlCommand(query, cnn))
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = _cnn
        cmd.CommandText = " insert into DOANHTHUTRONGNGAY(NgayThangNam,SoBenhNhan,DoanhThu,TyLe) values (@ngaythangnam,@sobenhnhan,@doanhthu,@tyle) "
        Dim para As OleDbParameter = cmd.Parameters.Add("@ngaythangnam", OleDbType.Date)
        para.Value = doanhthu.Thang

        para = cmd.Parameters.Add("@sobenhnhan", OleDbType.BigInt)
        para.Value = doanhthu.SoBenhNhan

        para = cmd.Parameters.Add("@doanhthu", OleDbType.BigInt)
        para.Value = doanhthu.DoanhThu

        para = cmd.Parameters.Add("@tyle", OleDbType.Single)
        para.Value = doanhthu.TyLe

       


        'goi thuc thi cau lenh
        Dim flag As Integer = 0

        flag = cmd.ExecuteNonQuery()
        _cnn.Close()
        If (flag > 0) Then
            Return 1
        Else
            Return 0
        End If
        'MessageBox.Show("a" + NV.MaHocSinh)

    End Function

End Class
